<template>
  <div class="login">
    <div class="title">
      <router-link to="/loginUser" tag="div" class="back">
        <span class="iconfont icon-fanhuijiantou"></span>
      </router-link>
    </div>

    <div class="log">
      <div class="icon">
        <span class="iconfont icon-shu"></span>
      </div>
    </div>
    <!-- 
    <div class="input_wrap">
      <input type="text" placeholder="手机号" />
    </div>
    <div class="input_wrap">
      <input type="password" placeholder="密码" />
    </div> -->

    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="注册手机号"
        placeholder=""
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="设置密码"
        placeholder=""
      />
      <van-field v-model="yzm" name="验证码" label="验证码" placeholder="" />

      <div style="margin: 16px">
        <van-button round block color="#FD9291" native-type="submit"
          >注册</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: "",
      yzm: "",
      checked: false,
    };
  },
  methods: {
    onSubmit() {
      if (this.username) {
        if (this.password) {
          if (this.yzm) {
            let user = {
              name: this.username,
              password: this.password,
            };
            window.localStorage.setItem("token", JSON.stringify(user));
            this.$toast.success('注册成功');
            this.$router.back()
          }else{
            this.$toast("请输入正确验证码")
          }
        }else{
            this.$toast("请设置密码")
          }
      }else{
            this.$toast("请输入手机号")
          }
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  .van-cell {
    width: 311px;
    margin: 10px auto;
    background-color: #f9f9f9;
    border-radius: 45px;
    &::after {
      position: relative;
    }
  }

  .van-button {
    width: 311px;
    margin: 20px auto;
  }
  .agreement {
    display: flex;
    margin-top: 20px;
    justify-content: center;
    padding-left: 16px;
  }
  .title {
    display: flex;
    .back {
      height: 44px;
      display: flex;
      padding-left: 16px;
      align-items: center;
      span {
        text-align: center;
        font-weight: 700;
        font-size: 24px;
      }
    }
  }
  .log {
    .icon {
      height: 180px;
      align-items: center;
      display: flex;
      justify-content: center;
      span {
        font-size: 80px;
        border: 1px solid #edd388;
        border-radius: 50%;
        color: #edd388;
      }
    }
  }
  .input_wrap {
    width: 285px;
    height: 48px;
    margin: 10px auto;
    background-color: #f9f9f9;
    border-radius: 48px;
    display: flex;
    align-items: center;
    padding-left: 18px;
    padding-right: 5px;
    input {
      background-color: #f9f9f9;
      height: 23px;
      font-size: 18px;
      width: 100%;
      border: none;
    }
  }
}
</style>